$(function () {
    if(typeof(orderStr) != "undefined" && orderStr && orderStr.length >1) {
        var order = JSON.parse(orderStr);
        var data = {"order": order};
        var html = template('orderTmp', data);
        document.getElementById('orderContent').innerHTML = html;
    }

    if(typeof(replystr) != "undefined" && replystr.length >1){
        var reply = JSON.parse(replystr);
        $('#jdremark').html(reply.remark);
        if(reply.caseState =='1'){
            $('#caseState').html("审核中");
        }else if(reply.caseState =='2'){
            $('#caseState').html("赔付中");
        }else {
            $('#caseState').html("复审结案");
            $('#closeReason').html(reply.closeReason);
        }
        $('#replyId').val(reply.id);
        var fileNames =  reply.jdAttachFile.split(",");
        $.each(fileNames , function(index ,item){
            item = $.trim(item);
            if(item && item.length >0)
            {
                var tmp =  "<span data='"+item+"'>附件：<input type=\"hidden\" name=\"attachFile\" value='"
                    +item +"'> <a href=\"javascript:void(0)\" onclick=\"downloadFile('"+item+"')\">"+item
                    +"</a> <i class=\"fa fa-fw fa-trash-o delete\" onclick=\"deleteFile('"+item+"')\"></i></span>";
                $('#jdFileListDiv').append(tmp);
            }
        });
    }
    var consignees,payment;
    if(typeof(consigneestr) != "undefined" && consigneestr && consigneestr.length >1){
        consignees = JSON.parse(consigneestr);
    }
    if(typeof(paymentstr) != "undefined" && paymentstr && paymentstr.length >1){
        payment = JSON.parse(paymentstr);
    }

    $("#consigneeGrid").dataTable({
        paging: false,//分页
        searching: false,
        bLengthChange: false,
        ordering: false,
        showNEntries:false,
        bInfo:false,
        data:consignees,
        columnDefs: [
            {
                defaultContent: "",
                targets: "_all"
            }
        ],
        columns:[
            {data:'merchantTradeNo'},
            {data:'consigneeIp'},
            {data:'consigneeGoods'},
            {data:'consigneeName'},
            {data:'consigneePhone'},
            {data:'consigneeAddress'}
        ]
    });


    $("#paymentGrid").dataTable({
        paging: false,//分页
        searching: false,
        bLengthChange: false,
        ordering: false,
        showNEntries:false,
        bInfo:false,
        data:payment,
        columnDefs: [
            {
                defaultContent: "",
                targets: "_all"
            }
        ],
        columns:[
            {data:'paymentState'},
            {data:'paymentAmount'},
            {data:'paymentCardPan'},
            {data:'paymentTime'},
        ]
    });
});

function downloadFile(fileName)
{
    window.location.href = queryPath+"/downloadFile.do?fileName="+fileName;
}